<template>
  <el-button type="text" v-bind="$attrs" @click="onClick">
    <slot>查看</slot>
  </el-button>
</template>

<script>
  import { checkCompUsePosition, isEmptyObj } from '../utils'
  import { TYPE_PREVIEW } from '../token'

  export default {
    name: 'CrudTableBtnPreview',
    props: {
      tableData: {
        type: Object,
        default: () => ({})
      },
      echoUrl: {
        type: String,
        default: ''
      },
      dialogTitle: {
        type: String,
        default: '查看'
      },
      isQuery: {
        type: Boolean,
        default: false
      }
    },
    inject: ['useBridge'],
    created() {
      checkCompUsePosition(isEmptyObj(this.tableData), 'CrudTableBtnPreview', 'CrudTableHandler')
    },
    methods: {
      onClick() {
        this.useBridge('showDialog', {
          type: TYPE_PREVIEW,
          title: this.dialogTitle,
          echoUrl: this.echoUrl,
          isQuery: this.isQuery,
          extraData: this.tableData.row
        })
      }
    },
  }
</script>

